package com.rstrulak.managedBeans.controllers;

import java.io.IOException;
import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.servlet.ServletException;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.rstrulak.model.User;
import com.rstrulak.utils.Constants;
import com.rstrulak.utils.JSFUtils;

/**
 * @author Robert Strulak Responsible for controlling menu
 * 
 */

@Component("menuController")
@Scope("request")
public class MenuController implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4538330001420146925L;
	
	private User loggedUser;

	@PostConstruct
	public void init(){
		loggedUser = JSFUtils.getLoggedUser();
	}
	
	public User getLoggedUser() {
		return loggedUser;
	}

	public void setLoggedUser(User loggerUser) {
		this.loggedUser = loggerUser;
	}


	public void goToProjectSite() throws ServletException, IOException{
		JSFUtils.flashScope().remove(Constants.CONTEXT_ID);
		JSFUtils.redirect("/protected/project.xhtml");
	}
	
	public void goToContextSite() throws ServletException, IOException{
		JSFUtils.flashScope().remove(Constants.PROJECT_ID);
		JSFUtils.redirect("/protected/context.xhtml");
	}
	

	public void goToTaskSite() throws ServletException, IOException{
//		JSFUtils.flashScope().remove(Contsants.PROJECT_ID);
		JSFUtils.redirect("/protected/task.xhtml");
	}
	
	public void goToNoteSite() throws ServletException, IOException{
//		JSFUtils.flashScope().remove(Contsants.PROJECT_ID);
		JSFUtils.redirect("/protected/note.xhtml");
	}

	public void goToCreateNoteSite() throws ServletException, IOException {
		JSFUtils.redirect("/protected/newNote.xhtml");
	}

	

}
